package com.castile.sdk.nifi.client.config;

import com.castile.sdk.nifi.client.config.entity.NiFiConfigEntity;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 基于本地 application.yaml配置的nifi配置获取
 *
 * @author castile
 * @date 2025-05-21 下午11:34
 */
@Service("local-nifi-config-manager")
public class LocalNiFiConfigManager implements NiFiConfigManager, InitializingBean {
    private Map<String, NiFiConfig> nifiConfigMap;

//    @Value("${app.nifi.configs}")
//    private List<NiFiConfigEntity> nifiConfigs;

    @Override
    public NiFiConfig getNiFiConfig(String name) {
        NiFiConfig niFiConfig = new NiFiConfig();
        niFiConfig.setName("dio-runtime");
        niFiConfig.setBaseUrl("https://localhost:8445");
        niFiConfig.setKeystoreFilename("/Users/castile/opt/projects/nifi/nifi-1.26.0/conf/keystore.jks");
        niFiConfig.setTruststoreFilename("/Users/castile/opt/projects/nifi/nifi-1.26.0/conf/truststore.jks");
        niFiConfig.setKeyPass("1Q6gXi/Bd9XahIZoNqlLpJNYQwiD15ue3YKVG0GJOs8");
        niFiConfig.setKeystorePass("1Q6gXi/Bd9XahIZoNqlLpJNYQwiD15ue3YKVG0GJOs8");
        niFiConfig.setTruststorePass("D5LScxoNf3m9NF739pAL/GfpB3qYmHHTV7Cg7W8vPL4");
        return niFiConfig;
//        return nifiConfigMap.get(name);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
//        nifiConfigs.forEach(nifiConfigEntity -> {
//            nifiConfigMap.put(nifiConfigEntity.getName(), new NiFiConfig(nifiConfigEntity.getName(), nifiConfigEntity.getBaseUrl()));
//        });
    }
}
